/**
 * @author wangxiaowei
 * 组织部发文列表
 */
var sort = null;
var grid = null;
var biaoti = '查阅文件';
function initzuzhibufawenlist(){
	
		 Ext.BLANK_IMAGE_URL=Ext.get('basePath').getValue()+"ajaxFramework/ext-2.1/resources/images/default/s.gif";

Ext.menu.RangeMenu.prototype.icons = {
	  gt: './ajaxFramework/ext-2.1/img/greater_then.png', 
	  lt: './ajaxFramework/ext-2.1/img/less_then.png',
	  eq: './ajaxFramework/ext-2.1/img/equals.png'
	};
Ext.grid.filter.StringFilter.prototype.icon = './ajaxFramework/ext-2.1/img/find.png';


	
var colModel = new Ext.grid.ColumnModel([
        {header:'收文编号',dataIndex:'shouwenbianhao',width:65,sortable:true},                               
		{header:'来文机关',dataIndex:'laiwenjiguan',width:55,sortable:true},
		{header:'来文字号',dataIndex:'laiwenzihao'},
		{header:'来文标题',dataIndex:'laiwenbiaoti'},
		{header:'来文日期',dataIndex:'laiwenriqi',menuDisabled : true,width:55,sortable:true},
		{header:'状态',dataIndex:'zhuangtai'},
		{header:'操作',dataIndex:'operate',menuDisabled : true}
]);



var filters = new Ext.grid.GridFilters({
		 cleanParams: function(p) {  // 清除参数的方法，要保留PagingToolbar分页用的两个参数
		   //var regex = new RegExp("^" + this.paramPrefix + "\[[0-9]+\]");
		   for(var key in p) {
		      if( key != 'start' && key != 'limit' )
		   //if(regex.test(key)) {
		    delete p[key];
		            //}
		               }
          },
	     buildQuery: function(filters) {	
		  // filters 就是getFilterData返回的值, 代码中push入去的对象
		  var p = {};
		  for(var i=0, len=filters.length; i<len; i++) {
		      var f = filters[i];
		      
		      // 取得在GridFilters中定义的filters中的一个filter
		      var filter = this.getFilter( f.field );
		      // 取得传递到server的参数名称
		      var name = (filter.paramName ? filter.paramName : filter.dataIndex);
		      var value = (filter.paramValue ? filter.paramValue : f.data['value']);
		      
		      if( value != '' ) p[ name ] = value;
		  }
		  var tablename = Ext.get('tablename').getValue();
			p['tablename']=tablename;
			var subtype = Ext.get('subtype').getValue();
			p['subtype']=subtype;
		  return p;
		   },	
		  filters:[
		 	{type: 'string',  dataIndex: 'laiwenjiguan'},
		 	{type: 'string',  dataIndex: 'laiwenzihao'},
		 	{type: 'string',  dataIndex: 'laiwenbiaoti'}
	]}); 

	var url = Ext.get('url').getValue();
	sort = new Ext.data.JsonStore({
		url:url,
		params:{tablename : 1,subtype : 2},
		fields:['shouwenbianhao','laiwenjiguan','laiwenzihao','laiwenbiaoti','laiwenriqi','operate','zhuangtai'],
		root:'root',
		totalProperty:'totalProperty'
	});
	var bbar = new Ext.PagingToolbar({
		pageSize:23,
		store:sort,
		displayInfo:true,
		plugins: filters,
		emptyMsg:'没有记录'
	});
	
	 grid = new Ext.grid.GridPanel({
		title:'查阅文件',
		cm:colModel,
		renderTo:'topic-grid',
		store:sort,
		loadMask:true,
		height:$(window).height()-17,
		bbar:bbar,
		plugins: filters,
		viewConfig:{
			forceFit:true,
			getRowClass:function(record,rowIndex,p,ds){
				if(record.get('state') == '是')
				{
					
					return 'green-row';
				}
				else if(record.get('state') == '中止')
				{
					
					return 'gray-row';
				}
			}
		}
	});
	sort.load({params:{start:0, limit: 23}});	
}

function typeselect(){
	var maintypeval = $("select[@name=maintype] option[@selected]").attr("value");
	var subtypeval = $("select[@name=subtype] option[@selected]").attr("value");
	if(maintypeval == "xingzhengshouwen"){
		document.getElementById("subdiv").style.display="";
		document.getElementById("tablename").value= maintypeval;
		document.getElementById("subtype").value= subtypeval;
		sort.reload({params:{start:0, limit: 23}});	
	}else{
		document.getElementById("subdiv").style.display="none";
		document.getElementById("tablename").value="dangweishouwen";
		document.getElementById("subtype").value='all';
		sort.reload({params:{start:0, limit: 23}});	
	}
}

function subtypechange(){
	var subtypeval = $("select[@name=subtype] option[@selected]").attr("value");
	document.getElementById("tablename").value="xingzhengshouwen";
	document.getElementById("subtype").value=subtypeval;
	sort.reload({
		params : {
			start : 0,
			limit : 23
		}
	});
}


	
	